﻿


namespace DATN2013.DATN.DAL
{
    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using System.Reflection;
    using Microsoft.ApplicationBlocks.Data;
    using DATN.ENTITIES;
    using DATN.COMMON;

    public class HangData
    {
        /// <summary>
        /// Gets the hang.
        /// </summary>
        /// <returns></returns>
        public IList<HangEN> GetHang()
        {
            HangEN hang = null;
            IList<HangEN> lstHang = new List<HangEN>();
            SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.DATNHangGetAll);
            while (reader.Read())
            {
                hang = new HangEN();

                if (!reader.IsDBNull(0))
                {
                    hang.IdHang = reader.GetInt32(0);
                }

                if (!reader.IsDBNull(1))
                {
                    hang.MaHang = reader.GetString(1);
                }

                if (!reader.IsDBNull(2))
                {
                    hang.TenHang = reader.GetString(2);
                }

                if (!reader.IsDBNull(3))
                {
                    hang.SoLuong = reader.GetInt32(3);
                }

                if (!reader.IsDBNull(4))
                {
                    hang.DonGia = reader.GetInt32(4);
                }

                if (!reader.IsDBNull(5))
                {
                    hang.IdLoaiHang = reader.GetInt32(5);
                }

                if (!reader.IsDBNull(6))
                {
                    hang.NgaySX = reader.GetString(6);
                }

                if (!reader.IsDBNull(7))
                {
                    hang.HanDung = reader.GetString(7);
                }

                if (!reader.IsDBNull(8))
                {
                    hang.ThanhPhan = reader.GetString(8);
                }

                lstHang.Add(hang);
            }

            reader.Close();
            reader.Dispose();
            return lstHang;
        }

        /// <summary>
        /// Gets the hang by unique identifier.
        /// </summary>
        /// <param name="IdHang">The unique identifier hang.</param>
        /// <returns></returns>
        public HangEN GetHangById(int IdHang)
        {
            HangEN hang = null;
            var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.DATNHangGetById, IdHang);
            while (reader.Read())
            {
                hang = new HangEN();

                if (!reader.IsDBNull(0))
                {
                    hang.IdHang = reader.GetInt32(0);
                }

                if (!reader.IsDBNull(1))
                {
                    hang.MaHang = reader.GetString(1);
                }

                if (!reader.IsDBNull(2))
                {
                    hang.TenHang = reader.GetString(2);
                }

                if (!reader.IsDBNull(3))
                {
                    hang.SoLuong = reader.GetInt32(3);
                }

                if (!reader.IsDBNull(4))
                {
                    hang.DonGia = reader.GetInt32(4);
                }

                if (!reader.IsDBNull(5))
                {
                    hang.IdLoaiHang = reader.GetInt32(5);
                }

                if (!reader.IsDBNull(6))
                {
                    hang.NgaySX = reader.GetString(6);
                }

                if (!reader.IsDBNull(7))
                {
                    hang.HanDung = reader.GetString(7);
                }

                if (!reader.IsDBNull(8))
                {
                    hang.ThanhPhan = reader.GetString(8);
                }
            }

            reader.Close();
            reader.Dispose();
            return hang;
        }
    }
}